//Created by Roman Clarkson for Jaws.Core.Web
//Original work Copyright(C) 2008.  All Rights Reserved.

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using Jaws.Core.Web.Attributes;

namespace Jaws.Core.Web.Controls
{
    public class Global : HttpApplication
    {
        public List<UserControlAttribute> PublicUserControlMembers { get; private set; }

        protected void Application_Start(object sender, EventArgs e)
        {
            PublicUserControlMembers = new List<UserControlAttribute>();
            GetPublicUserControls();
        }

        protected void Session_Start(object sender, EventArgs e)
        {
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }

        protected void Application_Error(object sender, EventArgs e)
        {
        }

        protected void Session_End(object sender, EventArgs e)
        {
        }

        protected void Application_End(object sender, EventArgs e)
        {
        }

        protected void GetPublicUserControls()
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            if (asm != null)
                foreach (Type t in asm.GetTypes())
                {
                    object[] attributes = t.GetCustomAttributes(typeof (UserControlAttribute), false);
                    foreach (object o in attributes)
                    {
                        if (o is UserControlAttribute)
                        {
                            PublicUserControlMembers.Add((UserControlAttribute) o);
                        }
                    }
                }
        }
    }
}